# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=liblangtag
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.7
pkgrel=2
pkgdesc="An interface library to access tags for identifying languages. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://bitbucket.org/tagoh/liblangtag'
msys2_references=(
  'archlinux: liblangtag'
)
license=('spdx:MPL-2.0 OR LGPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "autoconf-archive")
optdepends=("${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime: use with liblangtag-gobject")
source=("https://bitbucket.org/tagoh/liblangtag/downloads/${_realname}-${pkgver}.tar.bz2"
        "001-fix-build-on-mingw.patch"
        "002-update-ax-pthread-m4.patch"
        "003-aarch64.patch")
sha256sums=('5ed6bcd4ae3f3c05c912e62f216cd1a44123846147f729a49fb5668da51e030e'
            'ec43e6829c2e76ea8194f053d8bd38d3db6617df8c7bee79437df8d00dea9bed'
            '45a06e3c70cb374f50e180570b8e9bf484fdfba5caa4f0eee65ed60d63421c01'
            '4c4f7c6c12a3c3d4381f1f029d57ab1d54043f89d0c7ba18dba146157ad9ff29')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${_realname}-${pkgver}"

  apply_patch_with_msg \
    001-fix-build-on-mingw.patch \
    002-update-ax-pthread-m4.patch \
    003-aarch64.patch

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CFLAGS+=" -Wno-implicit-function-declaration" \
  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -d "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -p -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING* "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
